<template>
  <div>
    <home-header v-show="appType === '277'" :userinfo="userinfo" @help-click="helpClick" @strategy-click="strategyClick"/>
    <home-nav-control v-show="appType === '277'"/>
    <home-header-cat v-show="appType === 'cat'" :userinfo="userinfo" @help-click="helpClick" @strategy-click="strategyClick"/>
    <home-nav-list/>
    <home-popup :userinfo="userinfo" :show="show" @overlay-click="overlayClick"/>
  </div>
</template>

<script>
import HomeHeader from './childComps/HomeHeader.vue'
import HomeNavControl from './childComps/HomeNavControl.vue'
import HomeNavList from './childComps/HomeNavList.vue'
import HomePopup from './childComps/HomePopup.vue'
import { getHomePage } from '../../network/home'
import storage from '../../common/storage'
import { appType } from '../../assets/js/app'
import HomeHeaderCat from './childComps/HomeHeaderCat.vue'

  export default {
    components: { 
      HomeHeader,
        HomeNavControl,
        HomeNavList,
        HomePopup,
        HomeHeaderCat,
    },
    data() {
      return {
        tgid: '',
        userinfo: {},
        show: false,
        list: {
          openserver: false,
          discount: false,
          bt: false,
          web: false,
          active: false,
          vip: false,
          stopserver: false,
          tool: false,
          charge: false,
        },
        typeList: [],
        appType: null,
      }
    },
    created () {
      this.appType = appType()
      this.getHomeData()
      this.tgid = this.$cookies.get('tgid')
      if (storage.get(this.tgid)) {
        console.log(1)
        this.list = storage.get(this.tgid)
      }else {
        console.log(2)
        storage.set(this.tgid, this.list)
      }
    },
    mounted () {
      this.typeList = storage.get(this.tgid)
    },
    methods: {
      getHomeData() {
        getHomePage().then(res => {
          if(res.state === 'ok') {
            console.log(res)
            this.userinfo = res.data
            this.userinfo.tgid = this.$cookies.get('tgid')
            this.$store.commit('$_userinfo',res.data)
            this.$store.commit("$_isDc", res.data.is_dc);
          } else if (res.state === 'err') {
            if(res.msg === 'no_login') {
              this.$toast(res.msg)
              this.$router.replace('/login')
            }else {
              this.$toast(res.msg)
            }
          }
        })
      },
      helpClick() {
        this.show = !this.show
        // Toast(1)
      },
      overlayClick() {
        this.show = !this.show
      },
      strategyClick() {
        this.$router.push('/strategy')
      }
    },
  }
</script>

<style scoped>

</style>